package components.propertyCtrls
{
	import UIFree.controls.uif_label;
	import UIFree.uif_combobox;
	import UIFree.uif_component;
	
	import components.c_component;
	
	import flash.geom.Rectangle;
	
	public class c_comboBoxProperty extends c_propertyBase {
		public static const WEIGHT: Number = 53;
		private var _combobox: c_combobox;
		
		public function c_comboBoxProperty(parent:uif_component, aData: Object, y: int, a_height: int) {
			super(parent, aData, y, a_height);
		}
		
		override protected function createComponents(): void {
			super.createComponents();
			var inner: Rectangle = componentRect;
			_combobox = new c_combobox(this, inner.x, inner.y, inner.width, inner.height, 'combobox');
			_combobox.addEvent(uif_combobox.SELECTITEM, doChange);
		}
		
		public function get selectIndex(): int {
			return _combobox.selectIndex;
		}
		
		public function get selectObject(): Object {
			return _combobox.listControl.list[_combobox.selectIndex];
		}
		
		override protected function getValue():Object {
			return selectObject;
		}
		
		override protected function setData(value:Object):void {
			super.setData(value);
			if (_data.items) {
				var bi: Rectangle = _combobox.listControl.getInner();
				_combobox.listControl.attachList(_data.items, function(_area: uif_component, elem: Object, index: int): uif_component {
					return new c_comboboxItem(_area, elem, bi.x, bi.y + index * 20, bi.width, 20, 'combobox-item');
				});
				
				if (_data.value > -1)
					_combobox.selectIndex = _data.value;
			}
		}
	}
}